<?php

/**
 * This is the model class for table "lths_profit".
 *
 * The followings are the available columns in table 'lths_profit':
 * @property integer $id
 * @property string $trade_date
 * @property string $trade_staff
 * @property integer $trade_method
 * @property integer $trade_user_type
 * @property integer $producttype_code
 * @property string $product_id
 * @property double $bill_fee
 * @property double $phone_fee
 * @property double $check_profit
 * @property double $real_profit
 * @property string $remark
 * @property integer $treaty_id
 * @property integer $general_id
 * @property integer $trade_type
 * @property string $create_time
 * @property string $update_time
 *
 * The followings are the available model relations:
 * @property TradeGeneral $general
 * @property BTrademethod $tradeMethod
 * @property Producttype $producttypeCode
 * @property Product $product
 * @property User $tradeStaff
 * @property BTradetype $tradeType
 * @property TradeTreaty $treaty
 * @property BUsertype $tradeUserType
 */
class Profit extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Profit the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'lths_profit';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			//array('trade_date, trade_method, trade_user_type, producttype_code, trade_type', 'required'),
			//array('trade_method, trade_user_type, producttype_code, treaty_id, general_id, trade_type', 'numerical', 'integerOnly'=>true),
			//array('bill_fee, phone_fee, check_profit, real_profit', 'numerical'),
			//array('trade_staff', 'length', 'max'=>20),
			//array('product_id', 'length', 'max'=>15),
			//array('remark', 'length', 'max'=>500),
			//array('create_time, update_time', 'safe'),
			// The following rule is used by search().
			array('trade_date, trade_staff, trade_method, trade_user_type, producttype_code, product_id, bill_fee, phone_fee, check_profit, real_profit, remark, treaty_id, general_id, trade_type, create_time, update_time', 'safe'),
			// Please remove those attributes that should not be searched.
			array('id, trade_date, trade_staff, trade_method, trade_user_type, producttype_code, product_id, bill_fee, phone_fee, check_profit, real_profit, remark, treaty_id, general_id, trade_type, create_time, update_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		
		return array(
			'general' => array(self::BELONGS_TO, 'TradeGeneral', 'general_id'),
			'tradeMethod' => array(self::BELONGS_TO, 'BTrademethod', 'trade_method'),
			'producttypeCode' => array(self::BELONGS_TO, 'Producttype', 'producttype_code'),
			'product' => array(self::BELONGS_TO, 'Product', 'product_id'),
			'tradeStaff' => array(self::BELONGS_TO, 'User', 'trade_staff'),
			'tradeType' => array(self::BELONGS_TO, 'BTradetype', 'trade_type'),
			'treaty' => array(self::BELONGS_TO, 'TradeTreaty', 'treaty_id'),
			'tradeUserType' => array(self::BELONGS_TO, 'BUsertype', 'trade_user_type'),
		);
		
		return array();
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'trade_date' => '日期',
			'trade_staff' => '销售人',
			'trade_method' => '销售方式',
			'trade_user_type' => '用户类别',
			'producttype_code' => '产品类型',
			'product_id' => '规格型号',
			'bill_fee' => '合约预存款',
			'phone_fee' => '裸机销售价',
			'check_profit' => '考核毛利',
			'real_profit' => '实际毛利',
			'remark' => 'Remark',
			'treaty_id' => '合约/裸机',
			'general_id' => 'General',
			'trade_type' => '合约/裸机',
			'create_time' => 'Create Time',
			'update_time' => 'Update Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('trade_date',$this->trade_date,true);
		$criteria->compare('trade_staff',$this->trade_staff,true);
		$criteria->compare('trade_method',$this->trade_method);
		$criteria->compare('trade_user_type',$this->trade_user_type);
		$criteria->compare('producttype_code',$this->producttype_code);
		$criteria->compare('product_id',$this->product_id,true);
		$criteria->compare('bill_fee',$this->bill_fee);
		$criteria->compare('phone_fee',$this->phone_fee);
		$criteria->compare('check_profit',$this->check_profit);
		$criteria->compare('real_profit',$this->real_profit);
		$criteria->compare('remark',$this->remark,true);
		$criteria->compare('treaty_id',$this->treaty_id);
		$criteria->compare('general_id',$this->general_id);
		$criteria->compare('trade_type',$this->trade_type);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('update_time',$this->update_time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function behaviors(){  
    return array(  
        'CTimestampBehavior' => array(  
            'class' => 'zii.behaviors.CTimestampBehavior',  
            'createAttribute' => 'create_time',  
            'updateAttribute' => 'update_time',  
        )  
      );  
    } 
}